package com.example.myui.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.myui.R;
import com.example.myui.adapter.WebAdapter;

import java.util.ArrayList;

public class WebRecyclerViewActivity extends AppCompatActivity {

    private RecyclerView recyclerview;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_recycler_view);
        context = this;
//        initData();
        initView();
    }

    private ArrayList<String> initData() {
//        初始化评论数据
        ArrayList<String> comments = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            comments.add("comment :" + i);
        }
        return comments;
    }
//    http://api.tianapi.com/social/?key=861a794733dd2b057e415d822bef9586&num=10

    private void initView() {
        recyclerview = findViewById(R.id.recyclerview_web);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
        recyclerview.setLayoutManager(linearLayoutManager);
        WebAdapter adapter = new WebAdapter(context, initData());
        recyclerview.setAdapter(adapter);

    }
}
